package com.yan.test.work.testpaging3;

import android.content.Context;

import com.yan.test.work.testpaging3.net.BaseAPI;
import com.yan.test.work.testpaging3.net.JsonContervUtil;
import com.yan.test.work.testpaging3.net.callback.IOnLoadListener;
import com.yan.test.work.testpaging3.net.response.ResponseHandlerList;
import com.yan.test.work.testpaging3.net.response.ResponseModelList;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Create By : 'YWY'
 * On : 2024/4/2
 */
public class MainApi extends BaseAPI {

    private static final String URL = "/MjAyMi8xLzE2/v1/search/index";


    public void queryData(Context ctx , String keyWord , int from , int pageSize,IOnLoadListener<DataBean> listener){

        Map<String,Object> para = new HashMap<>();
        para.put("type","DEFAULT_ALL");
        para.put("keyword",keyWord);
        para.put("from",from);
        para.put("size",pageSize);

        postJson(ctx, URL, JsonContervUtil.objectToStr(para), new ResponseHandlerList<DataBean>() {
            @Override
            public void onSuccess(ResponseModelList<DataBean> responseModel, JSONObject dataJSONObject) {
                listener.onSuccess(responseModel.articles);
            }

            @Override
            public void onFailure(ResponseModelList<DataBean> responseModel) {
                listener.onFailure("查询失败");
            }
        });
    }
}
